<?php
namespace app\model;

use think\Model;

class BocCate extends Model{


    protected $table = 'boc_cate';


    public function get_cate($ctype='',$field='id,ctype,name,cover,thumb,remark,content'){
        return self::field($field)->where(['ctype'=>$ctype])->where(['status'=>1,'is_deleted'=>0])->order("sort desc,create_at desc")->select()->toarray();
    }

    public function get_sid_cate($ctype='',$field='id,sid,name'){
        return self::field($field)->where(['sid'=>$ctype])->where(['status'=>1,'is_deleted'=>0])->order("sort desc,create_at desc")->select()->toarray();
    }

    public function get_cate_list($cate_list,$product_list){
        foreach ($cate_list as $k=>$v) {
            foreach ($product_list as $kk=>$vv) {
                if($v['id']==$vv['cate_id']){
                    $cate_list[$k]['data'][] = $vv;
                }
            }
        }

        return $cate_list;
    }

    public function get_limit_cate($ctype=''){
        return self::field("id,ctype,name,cover,thumb,remark,content")->where(['ctype'=>$ctype])->where(['status'=>1,'deleted'=>0])->order("sort desc,create_at desc")->limit(3)->select()->toarray();
    }

    public function get_id($ctype=''){
        return self::field("name,remark")->where(['id'=>$ctype])->where(['status'=>1,'is_deleted'=>0])->order("sort desc,create_at desc")->findOrEmpty();
    }

    /*
     * ����id��������
     */
    public function get_name($cid){
        $list = self::field("id,name")->where(['status'=>1,'is_deleted'=>0])->select()->toArray();
        if(!empty($list)){
            foreach ($list as $k=>$v){
                if($v['id']==$cid){
                    return $v['name'];
                }
            }
        }
        return '0';

    }
}